package com.zz.tijian.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zz.tijian.entity.Orders;
import com.zz.tijian.entity.req.CheckAvailabilityDto;
import com.zz.tijian.entity.res.OrderCountByDateVO;
import com.zz.tijian.entity.res.OrderOfSetmealVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* @author 17958
* @description 针对表【orders】的数据库操作Mapper
* @createDate 2024-06-13 12:05:47
* @Entity generator.domain.Orders
*/
public interface OrdersMapper extends BaseMapper<Orders> {

    @Select("SELECT DATE(orderDate) AS orderDate, COUNT(*) AS orderCount " +
            "FROM orders " +
            "WHERE hpId = #{dto.hpId} AND smId = #{dto.smId} " +
            "AND orderDate BETWEEN #{dto.startDate} AND #{dto.endDate} " +
            "GROUP BY DATE(orderDate)")
    List<OrderCountByDateVO> selectOrderCountByDateRange(@Param("dto") CheckAvailabilityDto dto);
    @Select("SELECT o.*, s.name AS setmealName " +
            "FROM orders o " +
            "LEFT JOIN setmeal s ON o.smId = s.smId " +
            "WHERE o.userId = #{userId}")
    @Results({
            @Result(property = "orderId", column = "orderId"),
            @Result(property = "orderDate", column = "orderDate"),
            @Result(property = "userId", column = "userId"),
            @Result(property = "hpId", column = "hpId"),
            @Result(property = "smId", column = "smId"),
            @Result(property = "state", column = "state"),
            @Result(property = "setmealName", column = "setmealName")
    })
    List<OrderOfSetmealVO> selectOrderWithSetmeal(String userId);
}




